<template>
    <div> 
       <h1>排房信息增加</h1>
       <table class="table table-bordered">
        <tbody>
            <tr>
                <td align="right">门店</td>
                <td>
                    <select v-model="queryinfo.shopName">
                        <option value="">请选择</option>
                        <option value="北京市昌平区南口店">北京市昌平区南口店</option>
                        <option value="北京市顺义店">北京市顺义店</option>
                        <option value="北京市朝阳店">北京市朝阳店</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td align="right">房型</td>
                <td>
                    <select v-model="queryinfo.typeName">
                        <option value="">请选择</option>
                        <option :value="item.typeName" v-for="item in gethouse">{{ item.typeName }}</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td align="right">房号</td>
                <td>
                    <select v-model="queryinfo.number">
                        <option value="">请选择</option>
                        <option :value="item.number" v-for="item in numberlist">{{ item.number }}</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td align="right">姓名</td>
                <td>
                    <input type="text" v-model="queryinfo.userName"/>
                </td>
            </tr>
            <tr>
                <td align="right">身份证</td>
                <td>
                    <input type="text" v-model="queryinfo.idCord"/>
                </td>
            </tr>
            <tr>
                <td align="right">手机号</td>
                <td>
                    <input type="text" v-model="queryinfo.phone"/>
                </td>
            </tr>
            <tr>
                <td align="right">入住时间</td>
                <td>
                    <input type="date" v-model="queryinfo.checkintime"/>
                </td>
            </tr>
            <tr>
                <td align="right">离店时间</td>
                <td>
                    <input type="date" v-model="queryinfo.departureTime"/>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="button" value="添加" class="btn btn-success" @click="ok"/>
                </td>
            </tr>
        </tbody>
       </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import moment from 'moment';
import { ref,reactive,onMounted } from 'vue';
import { useRoute,useRouter } from 'vue-router';
const route=useRoute();
const router=useRouter();

let gethouse:any=ref([])

let numberlist:any=ref([])

onMounted(()=>{
    shownumber();
    showhouse();
})

const shownumber=()=>
{
    axios
    ({
        url:'/api/House/GetHouseNumber',
        method:'get'
    })
    .then(res=>{
        numberlist.value=res.data;
    })
    .catch(err=>{

    })
}


const showhouse=()=>
{
    axios
    ({
        url:'/api/House/GetHouse',
        method:'get'
    })
    .then(res=>{
        console.log(res);
        gethouse.value=res.data;
    })
    .catch(err=>{

    })
}

let queryinfo:any=reactive
({
  "shopName": "",
  "typeName": "",
  "number": "",
  "userName": "",
  "idCord": "",
  "phone": "",
  "checkintime": "",
  "departureTime": ""
})

const ok=()=>
{
    axios
    ({
        url:'/api/House/TerraceAdd',
        method:'post',
        data:queryinfo
    })
    .then(res=>{
        if(res.data==-1)
        {
            alert("房间号重复");
            return;
        }
        if(res.data>0)
        {
          alert("添加成功");
          router.push('terracesList');
          return;
        }
        else
        {
            alert("添加失败");
            return;
        }
    })
    .catch(err=>{

    })
}



</script>

<style scoped>

</style>